﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RN.ERP.DAL;
using RN.ERP.Entity.QD;
using Fly.Log;

using User_Log = Fly.Log.User_Log;
using User_Log_Data = Fly.Log.User_Log_Data;

namespace RN.ERP.BLL.QD.Utilities
{
    public class LogAndFlowHelper
    {
        QD_Context dbContext = new QD_Context();

        /// <summary>
        /// 企业、人员增加操作时同时向tb_flowcode表中插入一条数据
        /// </summary>
        /// <param name="flowcode"></param>
        /// <returns></returns>
        public bool AddFlowcode(Tb_FlowCode flowcode)
        {
            if (flowcode != null)
            {
                dbContext.FlowCodes.Add(flowcode);
                if (dbContext.SaveChanges() > 0)
                {
                    return true;
                }
            }
            return false;
        }

        /// <summary>
        /// 插入记录
        /// </summary>
        /// <param name="content"></param>
        /// <param name="objectid"></param>
        /// <param name="user"></param>
        public void InsertUserLog(string content, string objectid, string functionid, string functiontype)
        {
            UserLogManager.Log(new User_Log()
            {
                Content = content,
                ObjectId = objectid,
                FunctionId = functionid,
                FunctionType = functiontype,
                AppId = "98"
            });
        }

        /// <summary>
        /// 插入详细日志记录
        /// </summary>
        /// <param name="content"></param>
        /// <param name="objectid"></param>
        /// <param name="user"></param>
        public void InsertDetailUserLog(string content, string objectid, string functionid, string functiontype, User_Log log)
        {
            UserLogManager.Log(new User_Log()
            {
                Content = content,
                ObjectId = objectid,
                FunctionId = functionid,
                FunctionType = functiontype,
                AppId = "98",
                IsrtDate = log.IsrtDate,
                IsrtUserArea = log.IsrtUserArea,
                IsrtUserDept = log.IsrtUserDept,
                IsrtUser = log.IsrtUser,
                IsrtUserName = log.IsrtUserName,
                IsrtUserRole = log.IsrtUserRole,
                Notice = log.Notice
            });
        }

        public void InsertFlowLog(string content, string objectid, string functionid, string functiontype, string notice, object obj)
        {
            UserLogManager.Log(new User_Log()
            {

                Content = content,
                ObjectId = objectid,
                FunctionId = functionid,
                FunctionType = functiontype,
                Notice = notice,
                AppId = "98"
            }, obj);

        }
    }
}
